process.env.NODE_ENV = "production";

import { build as viteBuild } from "vite";
import chalk from "chalk";

const TAG = chalk.gray("build.mjs");

var viteConfigs = {};

// 不用谷歌离线统计，就不需要 service worker
// "main preload web sw".split(" ").forEach((k) => {
"main preload web".split(" ").forEach((k) => {
  viteConfigs[k] = `config/vite-${k}.config.js`;
});

async function buildElectron() {
  for (const [name, configPath] of Object.entries(viteConfigs)) {
    console.group(TAG, chalk.yellow(name));
    await viteBuild({ configFile: configPath, mode: process.env.NODE_ENV });
    console.groupEnd();
    console.log(); // for beautiful log.
  }
}

// bootstrap
await buildElectron();
